﻿using Cdx.Ui.App_Start;
using Cdx.Ui.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Cdx.Ui.Commands
{
    public class CommandLogin: CommandBase
    {
        private string m_User;
        private string m_Password;

        public CommandLogin(Model model, string user, string password): base(model)
        {
            m_User = user;
            m_Password = password;
        }

        public override void Execute()
        {
            try
            {
                Model.CurrentUser = Model.Engine.Login(m_User, m_Password);
                Model.Status.Message = string.Format("User {0} logged in to the system", m_User);
            }
            catch (Exception e)
            {
                Logger.Log.Error(e);
                Model.Status.Message = string.Format("Failed to log in {0} user", m_User);
            }
        }
    }
}